package com.findme.fecedetection.base;

import android.content.Context;
import android.net.Uri;
import android.util.AttributeSet;

import com.facebook.drawee.generic.GenericDraweeHierarchy;
import com.facebook.drawee.view.SimpleDraweeView;
import com.findme.fecedetection.interfaces.ImageViewPromise;


/**
 * Created by dab on 2017/9/29 0029 11:27
 * 图片的view
 */

public class ImageViewTang extends SimpleDraweeView implements ImageViewPromise {
//    private int mPlaceholder = R.mipmap.shangchuantupian;
//    private int mFailure = R.mipmap.jiazaishibai;
    private boolean isUsePlaceholder = true;

    public void setUsePlaceholder(boolean usePlaceholder) {
//        isUsePlaceholder = usePlaceholder;
//        GenericDraweeHierarchy hierarchy = getHierarchy();
//        hierarchy.setPlaceholderImage(0);
//        hierarchy.setFailureImage(0);
    }

    public ImageViewTang(Context context) {
        this(context, null);
    }

    public ImageViewTang(Context context, AttributeSet attrs) {
        this(context, attrs, 0);
    }

    public ImageViewTang(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        init();
    }

    private void init() {
        if (isUsePlaceholder) {
            GenericDraweeHierarchy hierarchy = getHierarchy();
//            hierarchy.setPlaceholderImage(mPlaceholder);
//            hierarchy.setFailureImage(mFailure);
        }
    }

    @Override
    public void setImageByRes(int res) {
        setUsePlaceholder(false);
//        isUsePlaceholder = false;
        super.setImageURI(Uri.parse("res://tanguy/" + res));
    }

    @Override
    public void setImageByFile(String path) {
        super.setImageURI(Uri.parse("file://" + path));
    }

    @Override
    public void setPlaceholderImage(int res) {
        GenericDraweeHierarchy hierarchy = getHierarchy();
        hierarchy.setPlaceholderImage(res);

    }

    @Override
    public void setFailureImage(int res) {
        GenericDraweeHierarchy hierarchy = getHierarchy();
        hierarchy.setFailureImage(res);

    }


}
